package com.zhongen.oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhongen.common.core.util.R;
import com.zhongen.common.security.util.SecurityUtils;
import com.zhongen.oa.entity.CustomerInfoEntity;
import com.zhongen.oa.mapper.CustomerInfoMapper;
import com.zhongen.oa.service.CustomerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 客户信息表
 *
 * @author Code Generator
 * @date 2024-03-12 13:06:34
 */
@Service
public class CustomerInfoServiceImpl extends ServiceImpl<CustomerInfoMapper, CustomerInfoEntity>
		implements CustomerInfoService {

	@Autowired
	CustomerInfoMapper customerInfoMapper;

	@Override
	public R importCustomerInfo(List<CustomerInfoEntity> customerInfoEntityList, BindingResult bindingResult) {
		// 通用校验获取失败的数据
		LocalDateTime now = LocalDateTime.now();
		String username = SecurityUtils.getUser().getUsername();
		for (CustomerInfoEntity customerInfoEntity : customerInfoEntityList) {
			customerInfoEntity.setCreateTime(now);
			customerInfoEntity.setCreateBy(username);
			customerInfoEntity.setUpdateTime(now);
			String status = customerInfoEntity.getStatus();
			if ("未联系".equals(status)) {
				customerInfoEntity.setStatus("3");
			}
			else if ("已联系，未拜访".equals(status)) {
				customerInfoEntity.setStatus("2");
			}
			else if ("已拜访".equals(status)) {
				customerInfoEntity.setStatus("1");
			}
			else if (status == null || "".equals(status)) {
				customerInfoEntity.setStatus("3");
			}
		}
		customerInfoMapper.insertAll(customerInfoEntityList);
		return R.ok();
	}

}
